<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>万息金融-后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="/admin/css/font.css">
    <link rel="stylesheet" href="/admin/css/xadmin.css">
    <script src="/admin/js/jquery.min.js"></script>
    <script src="/admin/js/myAjax.js"></script>
    <script src="/admin/js/common.js"></script>
    <script src="/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/admin/js/xadmin.js"></script>
    <script src="/admin/js/intercept.js"></script>
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <table id="test" lay-data="{toolbar: '#insert',id:'test'}" lay-filter="bcfilt"></table>
                </div>
            </div>
        </div>
    </div>

</div>
</div>
</body>
<script type="text/html" id="certificateImg">
    <img style="max-width: 50px" src="{{d.certificateImg}}">
</script>

<script type="text/html" id="operation">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="update">编辑</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete">删除</a>
</script>
<script type="text/html" id="insert">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"> 新增</button>
    </div>
</script>
<script>
    layui.use(['table', 'jquery'],
        function () {
            var table = layui.table
                , $ = layui.jquery;


            //头部工具栏事件:  新增
            table.on('toolbar(bcfilt)', function (obj) {

                switch (obj.event) {
                    case 'add':
                        layer.open({
                            title: '信息修改',
                            shade: 0.1,
                            area: ['1000px', '500px'],
                            type: 2,
                            content: './certificateAdd.html',
                        })
                        break;
                }
                ;
            });

            //荣誉认证
            table.render({
                elem: '#test'
                , page: true
                , url: ipAddress()+"/company/certificate/g"
                , method: 'get'
                , text: '没有数据'
                , toolbar: '#insert'
                , cols: [[
                      {field: 'certificateImg', minWidth: 150,event:'show',templet: '#certificateImg', title: '认证图片'}
                    , {field: 'createTime', minWidth: 100, title: '创建时间'}
                    , {field: 'updateTime', sort: true, title: '修改时间'}
                    , {field: 'remark', title: '批注'}
                    , {fixed: 'right', width: 160, align: 'center', toolbar: '#operation', title: '操作'}
                ]]
            });


            //单元格工具事件：编辑  删除
            table.on('tool(bcfilt)', function (obj) {
                var data = obj.data; //获得当前行数据 layui-laypage-count
                switch (obj.event) {
                    case 'show': layer.open({
                        type: 1,
                        title: false,
                        closeBtn: 0,
                        area: '516px',
                        skin: 'layui-layer-nobg', //没有背景色
                        shadeClose: true,
                        content: '<img style="display: inline-block; width: 100%; height: 100%;" src="'+data.certificateImg+'">'
                    });
                    break;
                    case 'delete':
                        layer.confirm('确认要删除吗？', function (index) {
                            let indx = table.cache.test.length;
                            //发异步删除数据

                            let res = myAjax(ipAddress()+'/company/certificate/d/'+data.id, {}, "delete");
                            let pg=$(".layui-laypage-curr").children().eq(1).text();
                            if (res.count == 1) {
                                if (indx == 1) {
                                    table.reload('test', {page: {curr: pg-1}})
                                } else {
                                    table.reload('test', {})
                                }
                                layer.msg('已删除!', {icon: 1, time: 1000});
                            } else {
                                layer.msg('删除失败!', {icon: 1, time: 1000});
                            }
                        });

                        break;
                    case 'update':
                        let res = myAjax(ipAddress()+'/company/certificate/g/'+data.id, {}, "get");
                        layer.open({
                            title: '信息修改',
                            shade: 0.1,
                            area: ['1000px', '500px'],
                            type: 2,
                            content: './certiUpdate.html',
                            success: function (layero, index) {
                                var body = layer.getChildFrame('body', index);
                                body.find('form').find('#Logo').attr("src", res.data.certificateImg);
                                body.find('form').find('#id').val(data.id);
                                body.find('form').find('#remark').val(res.data.remark);
                            }
                        })
                        break;
                };});






        });
</script>
</html>